<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下拉菜单 - 组件演示</title>
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../components/dropdown/dropdown.css">
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>🚀 openHarmony_Cordova_NutpiDesign</h1>
            <p class="subtitle">组件演示 - 下拉菜单</p>
        </header>

        <nav class="demo-nav">
            <a href="../index.html" class="nav-back">← 返回首页</a>
        </nav>

        <main class="main-content">
            <section class="demo-section">
                <h2>📋 下拉菜单演示</h2>
                
                <div class="demo-container">
                    <div class="demo-item">
                        <h3>单选下拉菜单</h3>
                        <div id="singleDropdown"></div>
                        <p class="demo-result">选择的值: <span id="singleResult">未选择</span></p>
                    </div>

                    <div class="demo-item">
                        <h3>多选下拉菜单</h3>
                        <div id="multiDropdown"></div>
                        <p class="demo-result">选择的值: <span id="multiResult">未选择</span></p>
                    </div>

                    <div class="demo-item">
                        <h3>带搜索的下拉菜单</h3>
                        <div id="searchDropdown"></div>
                        <p class="demo-result">选择的值: <span id="searchResult">未选择</span></p>
                    </div>

                    <div class="demo-item">
                        <h3>分组下拉菜单</h3>
                        <div id="groupDropdown"></div>
                        <p class="demo-result">选择的值: <span id="groupResult">未选择</span></p>
                    </div>
                </div>
            </section>

            <section class="demo-section">
                <h2>使用代码</h2>
                <pre><code>// 1. 引入文件
&lt;link rel="stylesheet" href="components/dropdown/dropdown.css"&gt;
&lt;script src="components/dropdown/dropdown.js"&lt;/script&gt;

// 2. 创建容器
&lt;div id="dropdownContainer"&lt;/div&gt;

// 3. 初始化下拉菜单
const dropdown = new Dropdown({
    container: '#dropdownContainer',
    options: [
        { label: '选项1', value: 'opt1' },
        { label: '选项2', value: 'opt2' },
        { label: '选项3', value: 'opt3' }
    ],
    onChange: (value) => {
        console.log('选择的值:', value);
    }
});

// 4. 获取选择的值
const value = dropdown.getValue();

// 5. 设置选择的值
dropdown.setValue('opt1');</code></pre>
            </section>
        </main>

        <footer class="footer">
            <p>&copy; 2025 OpenHarmony 三方库适配中心 | MIT License</p>
        </footer>
    </div>

    <script src="../components/dropdown/dropdown.js"></script>
    <script>
        // 单选下拉菜单
        const singleDropdown = new Dropdown({
            container: '#singleDropdown',
            options: [
                { label: '北京', value: 'beijing' },
                { label: '上海', value: 'shanghai' },
                { label: '广州', value: 'guangzhou' },
                { label: '深圳', value: 'shenzhen' }
            ],
            onChange: (value) => {
                document.getElementById('singleResult').textContent = value;
            }
        });

        // 多选下拉菜单
        const multiDropdown = new Dropdown({
            container: '#multiDropdown',
            multiple: true,
            options: [
                { label: 'JavaScript', value: 'js' },
                { label: 'Python', value: 'py' },
                { label: 'Java', value: 'java' },
                { label: 'Go', value: 'go' },
                { label: 'Rust', value: 'rust' }
            ],
            onChange: (values) => {
                document.getElementById('multiResult').textContent = 
                    values.length > 0 ? values.join(', ') : '未选择';
            }
        });

        // 带搜索的下拉菜单
        const searchDropdown = new Dropdown({
            container: '#searchDropdown',
            searchable: true,
            options: [
                { label: 'Apple', value: 'apple', description: '苹果' },
                { label: 'Banana', value: 'banana', description: '香蕉' },
                { label: 'Cherry', value: 'cherry', description: '樱桃' },
                { label: 'Date', value: 'date', description: '枣' },
                { label: 'Elderberry', value: 'elderberry', description: '接骨木浆果' }
            ],
            onChange: (value) => {
                document.getElementById('searchResult').textContent = value;
            }
        });

        // 分组下拉菜单
        const groupDropdown = new Dropdown({
            container: '#groupDropdown',
            options: [
                { group: '水果' },
                { label: '苹果', value: 'apple' },
                { label: '香蕉', value: 'banana' },
                { label: '橙子', value: 'orange' },
                { group: '蔬菜' },
                { label: '番茄', value: 'tomato' },
                { label: '黄瓜', value: 'cucumber' },
                { label: '胡萝卜', value: 'carrot' },
                { group: '肉类' },
                { label: '鸡肉', value: 'chicken' },
                { label: '牛肉', value: 'beef' }
            ],
            onChange: (value) => {
                document.getElementById('groupResult').textContent = value;
            }
        });
    </script>

    <style>
        .demo-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
            align-items: start;
        }

        .demo-item {
            background: var(--bg-light);
            padding: 16px;
            border-radius: 8px;
            overflow: visible;
            position: relative;
        }

        .demo-item h3 {
            margin-top: 0;
            margin-bottom: 16px;
            font-size: 16px;
            color: var(--text-primary);
        }

        .demo-item > div {
            margin-bottom: 12px;
            overflow: visible;
        }

        .demo-result {
            margin-top: 12px;
            padding: 8px 12px;
            background: var(--bg-white);
            border-radius: 4px;
            font-size: 13px;
            color: var(--text-secondary);
        }

        .demo-result span {
            color: var(--primary-color);
            font-weight: 600;
        }

        @media (max-width: 768px) {
            .demo-container {
                grid-template-columns: 1fr;
            }
        }
    </style>
</body>
</html>
